﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Ref_PostgresEFCore
{
    public static class StringHealper
    {
        public static string GetUnderScoreCase(this string str)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < str.Length; i++)
            {
                char chr = str[i];
                if (chr >= 'A' && chr <= 'Z')
                {
                    if (i == 0)
                    {
                        sb.Append(chr.ToString().ToLower());
                    }
                    else
                    {
                        sb.Append('_');
                        sb.Append(chr.ToString().ToLower());
                    }
                }
                else
                {
                    sb.Append(chr);
                }
            }
            return sb.ToString();
        }

        // 获取下划线命名法
        public static string GetAbbr(this string str)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < str.Length; i++)
            {
                char chr = str[i];
                if (chr >= 'A' && chr <= 'Z')
                {
                    sb.Append(chr.ToString().ToLower());
                }
            }
            return sb.ToString();
        }
    }
}
